package worlds
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import global.Global;
	import global.Managers;
	import global.WorldType;

	public class BaseWorld extends MovieClip
	{
		public var bgLayer					: Sprite;
		public var faceLayer				: Sprite;
		public var panelLayer				: Sprite;
		public var infoLayer				: Sprite;
		
		public static function get worldType():int {
			var type:int = WorldType.NONE_WORLD;
			var id:int = int(Global.config.TableID);
			if(id > 0) type = WorldType.TABLE_WORLD;
			else if(id <= 0 && id > -100) type = WorldType.MANAGEMENT_WORLD;
			else if(id <= -100 && id > -200) type = WorldType.KITCHEN_WORLD;
			else if(id <= -200 && id > -300) type = WorldType.COMMON_WORLD;
			return type;
		}
		
		public function BaseWorld()
		{
			super();
		}
		/**
		 * 根据约定好的ID段获取当前运行的World实例
		 * @return 
		 */
		public static function getInstance():BaseWorld {
			var instance:BaseWorld;
			switch(worldType) {
				case WorldType.TABLE_WORLD:
					instance = TableWorld.getInstance();
					break;
				case WorldType.MANAGEMENT_WORLD:
					instance = ManagementWorld.getInstance();
					break;
				case WorldType.KITCHEN_WORLD:
					instance = KitchenWorld.getInstance();
					break;
				case WorldType.COMMON_WORLD:
					instance = CommonWorld.getInstance();
					break;
			}
			return instance;
		}
		public function init():void {
			// 初始化各个显示层
			initLayers();
			// 初始化Managers
			Managers.init();
		}
		protected function initLayers():void {
			// 背景层，显示一些背景图片
			bgLayer = new Sprite();
			addChild(bgLayer);
			// 界面层，各种界面被称为faces
			faceLayer = new Sprite();
			addChild(faceLayer);
			// 面板层，用来盛放所有面板
			panelLayer = new Sprite();
			addChild(panelLayer);
			// 信息层，显示TIP用
			infoLayer = new Sprite();
			addChild(infoLayer);
		}
		
		public function getActiveContainer():Sprite {
			if(Managers.panelManager.openning) {
				return Managers.panelManager.currentPanel;
			} else {
				return Managers.faceManager.currentFace;
			}
		}
	}
}